﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Ozone.Views.Widget
{
    /// <summary>
    /// WindowWaiting.xaml 的交互逻辑
    /// </summary>
    public partial class WindowWaiting : Window
    {

        //全局等待对话框
        public static WindowWaiting g_WindowWaiting = null;
        public static async Task ShowWaitDlgAsync(ContentControl w, bool bShow, string title = "")
        {
            await Task.Run(() =>
            {
                w.Dispatcher.Invoke(delegate ()
                {
                    try
                    {
                        if (bShow)
                        {
                            g_WindowWaiting = new WindowWaiting(title);
                            g_WindowWaiting.ShowDialog();
                        }
                        else
                        {
                            g_WindowWaiting.Close();
                            g_WindowWaiting = null;
                        }
                    }
                    catch (Exception)
                    {
                        g_WindowWaiting.Close();
                    }
                });
            });

        }

        string content_ = "";
        public WindowWaiting(string content)
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;// 窗体居中

            InitializeComponent();
            txtContent.Text = content;
            content_ = content;

        }

        public void setTitle(string content)
        {
            txtContent.Text = content;
        }
    }
}
